﻿using System;
using System.Collections.Generic;
using System.Web;

using System.Configuration;
using System.Data;
using System.Data.Odbc;
using System.Security;
using System.Text;

using MiWebSite_Core;

using WLMCoreLibrary;
using System.Xml;
using System.Xml.Serialization;

namespace MWS_Blog
{


        [Serializable]
        [XmlType("BlogItem")]
        public class MiWebSiteBlogEntry : BaseClass
        {
            #region private fields
            private int _idCategoria;
            private String _titulo;
            private String _contenido;
            private String _contenidoExtra;
            private int _idImagen;
            private int _comentarios;
            private int _idGaleria;
            private String _lado;
            private int _visitas;
            private int _idSubdominio;
            private List<MiWebSiteBlogCategoria> _categorias;
            private List<MiWebSiteBlogTag> _tags;
            private String _postName;
            private int _idGeoTag;
            private DateTime _fechaInicioPublicacion;


            private DateTime _fechaFinalPublicacion;
            
            private List<MiWebSiteBlogComentary> _commentaryList = new List<MiWebSiteBlogComentary>();
            private string _userName;
            private string _userEmail;
            private string _listaTags;
            private string _listaCats;
            private GeoTag _geoTag;
            private List<MiWebSiteBlogEntry> _relatedItems;
            private List<MiWebSiteBlogComentary> _liComments;
            private List<MiWebSiteMediaImages> _imagenes;
            #endregion
            
            #region public properties
            
            [XmlIgnore()]
            public int idCategoria {get;set; }
            [XmlElement("title")]
            public String titulo {get;set; }
            public DateTime pubDate {get;set; }
            [XmlElement("description")]
            public String contenido {get;set; }
            [XmlElement("content")]
            public String contenidoExtra {get;set; }
            [XmlIgnore()]
            public int idImagen {get;set; }
            [XmlIgnore()]
            public int comentarios {get;set; }
            [XmlIgnore()]
            public int idGaleria {get;set; }
            [XmlIgnore()]
            public String lado {get;set; }
            [XmlIgnore()]
            public int visitas {get;set; }
            [XmlIgnore()]
            public int SubDominio {get;set; }
            public int idGeoTag
            {
               get;set;
                
            }
            public DateTime FechaInicioPublicacion
            {
               get;set;
     
            }
            public DateTime FechaFinalPublicacion
            {
               get;set;
        
            }
            [XmlElement("author")]
            public string UserName {get;set; }
            [XmlIgnore()]
            public string UserEmail {get;set; }
            [XmlElement("Tag")]
            public List<MiWebSiteBlogTag> Tags {get;set;  }
            [XmlElement("Categoria")]
            public List<MiWebSiteBlogCategoria> Categorias {get;set;  }
            [XmlIgnore()]
            public string ListaCategorias {get;set; }
            [XmlIgnore()]
            public string ListaTags {get;set; }
            [XmlIgnore()]
            public List<MiWebSiteBlogComentary> ComentaryList {get;set; }
            
            public List<MiWebSiteMediaImages> GaleriaImagenes
            {
               get;set;
                
            }


            [XmlElement("link")]
            public string URLEntry { get { return "http://" + CurrentDomain.SubDomain + "." + CurrentDomain.DomainName + "/" + fechaCreacion.ToString( "yyyy/MM/dd" ) + "/" + PostName + "/"; } set{} }
            [XmlElement("comments")]
            public string CommentsLink {get;set;  }
            
            public String PostName {get;set; }
            public GeoTag geoTag
            {
               get;set;
            
            }
            public List<MiWebSiteBlogEntry> RelatedItems
            {
               get;set;
       
            }
            #endregion

            #region constructors
            public MiWebSiteBlogEntry()
            {
            }

            public MiWebSiteBlogEntry(ref dbConnector ConexionDB)
            {
                ConexionDBInterna = ConexionDB;
                WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDB);
                id = classBinder.NewRecord("blogEntry");
                string queryString = "";
                queryString = "SELECT E.*,u.username as userName,u.email as userEmail FROM blogEntry E LEFT JOIN usuarios u on u.id=E.idUsuario WHERE E.id='" + id + "'";
                GetRecord(queryString);
                LoadAditionalData();
            }

            public MiWebSiteBlogEntry(int registryId,  ref dbConnector ConexionDB)
            {
                ConexionDBInterna = ConexionDB;
                string queryString = "";
                queryString = "SELECT E.*,u.username as userName,u.email as userEmail FROM blogEntry E LEFT JOIN usuarios u on u.id=E.idUsuario WHERE E.id='" + registryId + "'";
                WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDB);
                GetRecord(queryString);
                LoadAditionalData();
                cargarTagsCats();

            }

            public MiWebSiteBlogEntry(string EntryPostName, ref dbConnector ConexionDB)
            {
                ConexionDBInterna = ConexionDB;
                string queryString = "";
                queryString = "SELECT E.*,u.username as userName,u.email as userEmail FROM blogEntry E LEFT JOIN usuarios u on u.id=E.idUsuario WHERE E.postname='" + EntryPostName + "'";
                WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDB);
                GetRecord(queryString);
                LoadAditionalData();
                queryString = "SELECT id from blogComentarios WHERE idEntry='" + id + "' order by fechaCreacion";
                OdbcDataReader reader = ConexionDBInterna.ExecuteReader(queryString);
                while (reader.Read())
                {
                    ComentaryList.Add(new MiWebSiteBlogComentary(Convert.ToInt32(reader["id"].ToString()),ref ConexionDB));
                }


                cargarTagsCats();


            }
            #endregion

            #region public methods
            public void LoadAditionalData()
            {
                if (idGaleria != 0)
                    GaleriaImagenes = new MiWebSiteMediaImagesCollection(idGaleria, ref ConexionDBInterna).Elementos;
                if (idGeoTag != 0)
                    geoTag = new GeoTag(idGeoTag, ref ConexionDBInterna);
            }

            public void CargarRelacionados()
            {
                RelatedItems = new MiWebSiteBlogEntryCollection(this,ref ConexionDBInterna).BlogEntryList;
            }

            public void Save(bool GuardarTagsCats)
            {
                titulo = WLMFunctions.comillas(titulo);
                contenido = WLMFunctions.comillas(contenido);
                contenidoExtra = WLMFunctions.comillas(contenidoExtra);
                this.UpdateBind();
                if (GuardarTagsCats)
                {
                    CheckCats();
                    CheckTags();
                }
                HttpContext.Current.Application.Remove("BlogPortada");
                HttpContext.Current.Application.Remove("UltimaNoticia");
                HttpContext.Current.Application.Remove("NubeTags");
            }

            public void Delete()
            {
                string queryString = "";
                queryString = "DELETE FROM blogEntry WHERE id=\"" + id + "\"";
                ConexionDBInterna.ExecuteCommand(queryString);
                HttpContext.Current.Session.Remove("BlogPortada");

            }

            public void cargarTagsCats()
            {
                Categorias = new List<MiWebSiteBlogCategoria>();
                Tags = new List<MiWebSiteBlogTag>();
                foreach (MiWebSiteBlogTag tag in new MiWebSiteBlogTagCollection(this,ref ConexionDBInterna).Elementos)
                {
                    Tags.Add(tag);
                }
                foreach(MiWebSiteBlogCategoria cat in  new MiWebSiteBlogCategoriaCollection(this,ref ConexionDBInterna).Elementos){
                    Categorias.Add(cat);
                }
            }

            public string Portada()
            {
                if (Convert.ToString(HttpContext.Current.Application["UltimaNoticia"]) == "")
                {
                    StringBuilder salidaApplication = new StringBuilder();
                    MiWebSiteTemplate skin = new MiWebSiteTemplate("UltimaNoticia",ref ConexionDBInterna);
                    salidaApplication.Append("<div>");

                    string skinStr = skin.template.ToString();
                    skinStr = skinStr.Replace("[LINK]", URLEntry);
                    skinStr = skinStr.Replace("[TITULO]", titulo);
                    skinStr = skinStr.Replace("[NOVISITAS]", visitas.ToString());
                    skinStr = skinStr.Replace("[NOCOMENTARIOS]", comentarios.ToString());
                    skinStr = skinStr.Replace("[CONTENIDO]", contenido);
                    skinStr = skinStr.Replace("[IDIMAGEN]", idImagen.ToString());

                    salidaApplication.Append(skinStr);

                    salidaApplication.Append("</div>");


                    HttpContext.Current.Application["UltimaNoticia"] = salidaApplication.ToString();
                }

                return HttpContext.Current.Application["UltimaNoticia"].ToString();
            }

            public String Detalle(string plantilla, bool contenidoCompleto)
            {

                string skinBlog = plantilla;
                skinBlog = skinBlog.Replace("[LINK]", URLEntry);
                skinBlog = skinBlog.Replace("[URL]", ConfigurationManager.AppSettings["siteURL"]);
                if (CurrentUser.NivelUsuario >= 5)
                    skinBlog = skinBlog.Replace("[TITULO]", titulo + " <a href=\"" + URLEntry + "?admin=1\" id='BotonAccion'> Editar este Post</a>");
                else
                    skinBlog = skinBlog.Replace("[TITULO]", titulo);


                skinBlog = skinBlog.Replace("[FECHA]", fechaCreacion.ToString());
                skinBlog = skinBlog.Replace("[DIA]", fechaCreacion.Day.ToString());
                // skinBlog = skinBlog.Replace("[MES]", WLMFunctions.FechaMes(fechaCreacion, false));
                skinBlog = skinBlog.Replace("[ANO]", fechaCreacion.Year.ToString());
                skinBlog = skinBlog.Replace("[HORA]", fechaCreacion.TimeOfDay.ToString());
                skinBlog = skinBlog.Replace("[AUTOR]", "<a href='/blog/autor/" + UserName + ".aspx'>" + UserName + "</a>");
                if (idImagen == 0)
                    skinBlog = skinBlog.Replace("IMGVISIBLE", "display:none;");
                skinBlog = skinBlog.Replace("[IDIMAGEN]", idImagen.ToString());
                skinBlog = skinBlog.Replace("[NOCOMENTARIOS]", comentarios.ToString());
                skinBlog = skinBlog.Replace("[TAGS]", ligasTags());
                skinBlog = skinBlog.Replace("[CATEGORIAS]", ligasCategorias());

                if (contenidoCompleto)
                {
                    skinBlog = skinBlog.Replace("[CONTENIDO]", contenido + contenidoExtra);
                    skinBlog = skinBlog.Replace("[COMENTARIOS]", LlenadoComentarios());
                }
                else
                {
                    skinBlog = skinBlog.Replace("[COMENTARIOS]", "");
                    if (contenidoExtra != null)
                        skinBlog = skinBlog.Replace("[CONTENIDO]", contenido + "<br><a href='" + URLEntry + "'>leer mas...</a>");
                    else
                        skinBlog = skinBlog.Replace("[CONTENIDO]", contenido);
                }

                return skinBlog;
            }
            #endregion

            #region Private Methods
            private void GetRecord(string queryString)
            {
                OdbcDataReader reader = ConexionDBInterna.ExecuteReader(queryString);
                if (reader.HasRows)
                {
                    if (!reader.IsDBNull(reader.GetOrdinal("id")))
                        id = (System.Int32)reader["id"];
                    if ( !reader.IsDBNull( reader.GetOrdinal( "fechaCreacion" ) ) )
                    {
                        fechaCreacion = Convert.ToDateTime( reader["fechaCreacion"] );
                        pubDate = Convert.ToDateTime( reader["fechaCreacion"] );
                    }
                    if (!reader.IsDBNull(reader.GetOrdinal("fechaModificacion"))) 
                        fechaModificacion = Convert.ToDateTime(reader["fechaModificacion"]); 
                    if (!reader.IsDBNull(reader.GetOrdinal("idUsuarioModificacion"))) 
                        idUsuarioModificacion = (System.Int32)reader["idUsuarioModificacion"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idUsuario")))
                        idUsuario = (System.Int32)reader["idUsuario"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idCategoria")))
                        idCategoria = (System.Int32)reader["idCategoria"];
                    if (!reader.IsDBNull(reader.GetOrdinal("titulo")))
                        titulo = (System.String)reader["titulo"];
                    if (!reader.IsDBNull(reader.GetOrdinal("contenido")))
                        contenido = (System.String)reader["contenido"];
                    if (!reader.IsDBNull(reader.GetOrdinal("contenidoExtra")))
                        contenidoExtra = (System.String)reader["contenidoExtra"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idImagen")))
                        idImagen = (System.Int32)reader["idImagen"];
                    if (!reader.IsDBNull(reader.GetOrdinal("comentarios")))
                        comentarios = (System.Int32)reader["comentarios"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idGaleria")))
                        idGaleria = (System.Int32)reader["idGaleria"];
                    if (!reader.IsDBNull(reader.GetOrdinal("lado")))
                        lado = (System.String)reader["lado"];
                    if (!reader.IsDBNull(reader.GetOrdinal("visitas")))
                        visitas = (System.Int32)reader["visitas"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idDominio")))
                        SubDominio = (System.Int32)reader["idDominio"];
                    if (!reader.IsDBNull(reader.GetOrdinal("UserName")))
                        UserName = (System.String)reader["UserName"];
                    if (!reader.IsDBNull(reader.GetOrdinal("UserEmail")))
                        UserEmail = (System.String)reader["UserEmail"];
                    //if (!reader.IsDBNull(reader.GetOrdinal("tags")))
                    //    tags = (System.String)reader["tags"];
                    //if (!reader.IsDBNull(reader.GetOrdinal("categorias")))
                    //    categorias = (System.String)reader["categorias"];
                    if (!reader.IsDBNull(reader.GetOrdinal("postName")))
                        PostName = (System.String)reader["postName"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idGeoTag")))
                        idGeoTag = (System.Int32)reader["idGeoTag"];
                    if (!reader.IsDBNull(reader.GetOrdinal("fechaFinalPublicacion")))
                        FechaFinalPublicacion = Convert.ToDateTime(reader["fechaFinalPublicacion"]);
                    if (!reader.IsDBNull(reader.GetOrdinal("fechaInicioPublicacion")))
                        FechaInicioPublicacion = Convert.ToDateTime(reader["fechaInicioPublicacion"]);
                }
            }

            protected override void UpdateBind()
            {
                StringBuilder strCommand = new StringBuilder();
                strCommand.Append("UPDATE blogEntry set "); strCommand.Append("fechaModificacion='" + this.fechaModificacion.ToString("yyyy-MM-dd HH:mm:ss") + "'"); strCommand.Append(",idUsuarioModificacion=\"" + idUsuarioModificacion.ToString() + "\"");

                strCommand.Append(",idUsuario=\"" + this.idUsuario.ToString() + "\"");
                strCommand.Append(",idCategoria=\"" + this.idCategoria.ToString() + "\"");
                strCommand.Append(",titulo=\"" + this.titulo.ToString() + "\"");
                strCommand.Append(",contenido=\"" + this.contenido.ToString() + "\"");
                if (contenidoExtra != null)
                    strCommand.Append(",contenidoExtra=\"" + this.contenidoExtra.ToString()+ "\"");
                strCommand.Append(",idImagen=\"" + this.idImagen.ToString() + "\"");
                strCommand.Append(",comentarios=\"" + this.comentarios.ToString() + "\"");
                strCommand.Append(",idGaleria=\"" + this.idGaleria.ToString() + "\"");
                strCommand.Append(",lado=\"" + this.lado.ToString() + "\"");
                strCommand.Append(",visitas=\"" + this.visitas.ToString() + "\"");
                strCommand.Append(",idDominio=\"" + this.SubDominio.ToString() + "\"");
                //strCommand.Append(",tags=\"" + tags.ToString() + "\"");
                //strCommand.Append(",categorias=\"" + categorias.ToString() + "\"");
                strCommand.Append(",postName=\"" + PostName.ToString() + "\"");
                strCommand.Append(",idGeoTag=\"" + this.idGeoTag.ToString() + "\"");
                strCommand.Append(",FechaInicioPublicacion='" + this.FechaInicioPublicacion.ToString("yyyy-MM-dd HH:mm:ss") + "'");
                strCommand.Append(",FechaFinalPublicacion='" + this.FechaFinalPublicacion.ToString("yyyy-MM-dd HH:mm:ss") + "'");
                strCommand.Append(" WHERE id=\"" + this.id + "\"");
                ConexionDBInterna.ExecuteCommand(strCommand.ToString());
            }

            private string ligasCategorias()
            {
                StringBuilder salida = new StringBuilder();
                int x = 0;
                foreach (MiWebSiteBlogCategoria item in _categorias)
                {
                    salida.Append("<a href='/blog/categoria/" + item.NombreCategoria.Replace(" ", "-") + ".aspx'>" + item.NombreCategoria + "</a>");
                    if (x != _categorias.Count - 1)
                    {
                        salida.Append(", ");
                    }
                    x++;
                }
                return salida.ToString();
            }

            private string ligasTags()
            {
                StringBuilder salida = new StringBuilder();
                int x = 0;
                foreach (MiWebSiteBlogTag item in _tags)
                {
                    salida.Append("<a href='/blog/tag/" + item.NombreTag.Replace(" ", "-") + ".aspx'>" + item.NombreTag + "</a>");
                    if (x != _tags.Count - 1)
                    {
                        salida.Append(", ");
                    }
                    x++;
                }
                return salida.ToString();
            }

            private string listadoCategorias()
            {
                StringBuilder salida = new StringBuilder();
                int x = 0;
                foreach (MiWebSiteBlogCategoria item in _categorias)
                {
                    salida.Append(item.NombreCategoria);
                    if (x != _categorias.Count - 1)
                    {
                        salida.Append(", ");
                    }
                    x++;
                }
                return salida.ToString();
            }

            private string listadoTags()
            {
                StringBuilder salida = new StringBuilder();
                int x = 0;
                foreach (MiWebSiteBlogTag item in _tags)
                {
                    salida.Append(item.NombreTag);
                    if (x != _tags.Count - 1)
                    {
                        salida.Append(", ");
                    }
                    x++;
                }
                return salida.ToString();
            }

            private string LlenadoComentarios()
            {


                StringBuilder comentarios = new StringBuilder();
                string skinComentario = "";// MiWebSiteFunctions.LoadTemplate("BlogComment.htm");
                int x = 0, y = 1;
                foreach (MiWebSiteBlogComentary comm in ComentaryList)
                {
                    if (comm.Activo)
                    {
                        string comment = skinComentario.ToString();
                        if (CurrentUser.NivelUsuario > 5)
                            comment = comment.Replace("[CONTENIDO]", "<a href='?id=" + id.ToString() + "&borrarComentario=" + comm.id.ToString() + "' id='BotonAccion'>Borrar Comentario</a><br>" + comm.contenido);
                        else
                            comment = comment.Replace("[CONTENIDO]", comm.contenido);
                        comment = comment.Replace("[EMAIL]", comm.email);
                        comment = comment.Replace("[FECHA]", comm.fechaCreacion.ToString());
                        comment = comment.Replace("[DIA]", comm.fechaCreacion.Day.ToString());
                        comment = comment.Replace("[MES]", comm.fechaCreacion.Month.ToString());
                        comment = comment.Replace("[ANO]", comm.fechaCreacion.Year.ToString());
                        comment = comment.Replace("[HORA]", comm.fechaCreacion.TimeOfDay.ToString());
                        comment = comment.Replace("[AUTOR]", comm.nombre);
                        comment = comment.Replace("[IDCOMENTARIO]", comm.id.ToString());
                        comment = comment.Replace("[NOCOMENTARIO]", y.ToString());
                        comment = comment.Replace("[LINK]", ConfigurationManager.AppSettings["MainSiteURL"] + URLEntry + "#comentario" + id);
                        comentarios.Append(comment);


                        x++;
                        y++;
                        if (x == 5)
                        {
                            //comentarios.Append(MiWebSiteFunctions.ShowBanner(2));
                            x = 0;
                        }
                    }
                }
                return comentarios.ToString();
            }

            public void CheckTags()
            {
                if (_listaTags != null)
                {
                    Tags = new List<MiWebSiteBlogTag>();
                    ConexionDBInterna.ExecuteCommand("DELETE FROM BLOGTAG2ENTRY WHERE idEntry='" + id + "'");
                    string[] arregloTags = _listaTags.Split(',');
                    foreach (string tagActual in arregloTags)
                    {
                        int temp;
                        string tagActualLimpio = MiWebSiteFunctions.tituloaPostName(tagActual.Trim());
                        if (!WLMFunctions.TryParseToInt(tagActualLimpio, out temp))
                        {
                            if (tagActualLimpio != "")
                            {
                                MiWebSiteBlogTag tag = new MiWebSiteBlogTag(tagActualLimpio,ref ConexionDBInterna);
                                if (tag.id == 0)
                                {
                                    tag = new MiWebSiteBlogTag(ref ConexionDBInterna);
                                    tag.NombreTag = tagActual.Trim();
                                    tag.SystemName = tagActualLimpio;
                                    tag.Save();
                                }
                                temp = tag.id;
                                // tag.Dispose();
                            }
                        }

                        MiWebSiteBlogTag nuevoTag = new MiWebSiteBlogTag(temp,ref ConexionDBInterna);
                        MiWebSiteBlogTag cusTemp = _tags.Find(delegate(MiWebSiteBlogTag _cus)
                        {
                            if (_cus.id == nuevoTag.id)
                            {
                                return true;
                            }
                            return false;
                        });
                        if (cusTemp == null)
                        {
                            MiWebSiteBlogTag2Entry tag2 = new MiWebSiteBlogTag2Entry(ref ConexionDBInterna);
                            tag2.idEntry = id;
                            tag2.idTag = nuevoTag.id;
                            tag2.Save();
                            Tags.Add(nuevoTag);
                        }
                        //else
                        // nuevoTag.Dispose();
                    }
                }

            }

            public void CheckCats()
            {
                if (_listaTags !=null)
                {
                    Categorias = new List<MiWebSiteBlogCategoria>();
                    ConexionDBInterna.ExecuteCommand("DELETE FROM BLOGCAT2ENTRY WHERE idEntry='" + id + "'");
                    string[] arregloTags = _listaCats.Split(',');
                    foreach (string tagActual in arregloTags)
                    {
                        string catActualLimpio = MiWebSiteFunctions.tituloaPostName(tagActual.Trim());
                        int temp;
                        if (!WLMFunctions.TryParseToInt(catActualLimpio, out temp))
                        {
                            if (catActualLimpio != "")
                            {
                                MiWebSiteBlogCategoria cat = new MiWebSiteBlogCategoria(catActualLimpio,ref ConexionDBInterna);
                                if (cat.id == 0)
                                {
                                    cat = new MiWebSiteBlogCategoria(ref ConexionDBInterna);
                                    cat.NombreCategoria = tagActual.Trim();
                                    cat.SystemName = catActualLimpio;
                                    cat.Save();
                                }
                                temp = cat.id;
                                cat.Dispose();
                            }
                        }

                        MiWebSiteBlogCategoria newCat = new MiWebSiteBlogCategoria(temp,ref ConexionDBInterna);

                        MiWebSiteBlogCategoria cusTemp = _categorias.Find(delegate(MiWebSiteBlogCategoria _cus)
                        {
                            if (_cus.id == newCat.id)
                            {
                                return true;
                            }
                            return false;
                        });
                        if (cusTemp == null)
                        {
                            MiWebSiteBlogCat2Entry cat2 = new MiWebSiteBlogCat2Entry(ref ConexionDBInterna);
                            cat2.idEntry = id;
                            cat2.idCat = newCat.id;
                            cat2.Save();
                            Categorias.Add(newCat);
                        }
                        else
                        {
                            newCat.Dispose();
                        }
                    }
                }

            }

            #endregion
        }

        public class MiWebSiteBlogComentary : BaseClass
        {
            #region private fields
            private String _nombre;
            private String _email;
            private String _url;
            private String _contenido;
            private int _idEntry;
            private int _idDominio;
            private string _tituloEntry;
            private DateTime _fechaEntry;
            private String _postName;
            private bool _activo;
            #endregion

            #region public properties
            [XmlElement("wp.comment_id")]
            public Int32 id2 {get;set;}
            public String nombre {get;set; }
            public String email {get;set; }
            public String url {get;set; }
            public String contenido {get;set; }
            public int idEntry {get;set; }
            public int SubDominio {get;set; }
            public string TituloEntry {get;set; }
            public int idDominio{get;set;}
            public DateTime FechaEntry {get;set; }
            public string Link {get;set; }
            public String PostName {get;set; }
            public bool Activo {get;set; }
            #endregion

            #region constructors
            public MiWebSiteBlogComentary() { }

            public MiWebSiteBlogComentary(ref dbConnector ConexionDB)
            {
                ConexionDBInterna = ConexionDB;
                WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDB);
                id = classBinder.NewRecord("blogComentarios");
                string queryString = "";
                queryString = "SELECT c.*,b.titulo as TituloEntry,b.fechaCreacion as FechaEntry,b.postname as PostName FROM blogComentarios c left join blogEntry b on b.id=c.idEntry WHERE c.id=\"" + id + "\"";
                GetRecord(queryString);
            }

            public MiWebSiteBlogComentary(int registryId, ref dbConnector ConexionDB)
            {
                ConexionDBInterna = ConexionDB;
                string queryString = "";
                queryString = "SELECT c.*,b.titulo as TituloEntry,b.fechaCreacion as FechaEntry, b.postname as PostName FROM blogComentarios c left join blogEntry b on b.id=c.idEntry WHERE c.id='" + registryId + "'";
                WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDB);
                GetRecord(queryString);
            }
            #endregion

            #region public methods

            public void Delete()
            {
                string queryString = "";
                queryString = "DELETE FROM blogComentarios WHERE id=\"" + id + "\"";
                ConexionDBInterna.ExecuteCommand(queryString);

            }
            #endregion

            #region Private Methods
            private void GetRecord(string queryString)
            {
                OdbcDataReader reader = ConexionDBInterna.ExecuteReader(queryString);
                if (reader.HasRows)
                {
                    if (!reader.IsDBNull(reader.GetOrdinal("id")))
                        id = (System.Int32)reader["id"];
                    if (!reader.IsDBNull(reader.GetOrdinal("fechaCreacion")))
                        fechaCreacion = Convert.ToDateTime(reader["fechaCreacion"]); if (!reader.IsDBNull(reader.GetOrdinal("fechaModificacion"))) fechaModificacion = Convert.ToDateTime(reader["fechaModificacion"]); if (!reader.IsDBNull(reader.GetOrdinal("idUsuarioModificacion"))) idUsuarioModificacion = (System.Int32)reader["idUsuarioModificacion"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idUsuario")))
                        idUsuario = (System.Int32)reader["idUsuario"];
                    if (!reader.IsDBNull(reader.GetOrdinal("nombre")))
                        nombre = (System.String)reader["nombre"];
                    if (!reader.IsDBNull(reader.GetOrdinal("email")))
                        email = (System.String)reader["email"];
                    if (!reader.IsDBNull(reader.GetOrdinal("url")))
                        url = (System.String)reader["url"];
                    if (!reader.IsDBNull(reader.GetOrdinal("contenido")))
                        contenido = (System.String)reader["contenido"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idEntry")))
                        idEntry = (System.Int32)reader["idEntry"];
                    if (!reader.IsDBNull(reader.GetOrdinal("TituloEntry")))
                        TituloEntry = (System.String)reader["TituloEntry"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idDominio")))
                        idDominio = (System.Int32)reader["idDominio"];
                    if (!reader.IsDBNull(reader.GetOrdinal("FechaEntry")))
                        FechaEntry = Convert.ToDateTime(reader["FechaEntry"]);
                    if (!reader.IsDBNull(reader.GetOrdinal("postName")))
                        PostName = (System.String)reader["postName"];
                    if (!reader.IsDBNull(reader.GetOrdinal("activo")))
                        Activo = Convert.ToBoolean(reader["activo"]);
                }
            }

            protected override void UpdateBind()
            {
                email = WLMFunctions.comillas(_email);
                nombre = WLMFunctions.comillas(_nombre);
                contenido = WLMFunctions.comillas(_contenido);

                StringBuilder strCommand = new StringBuilder();
                strCommand.Append("UPDATE blogComentarios set "); strCommand.Append("fechaModificacion='" + this.fechaModificacion.ToString("yyyy-MM-dd HH:mm:ss") + "'"); strCommand.Append(",idUsuarioModificacion=\"" + idUsuarioModificacion.ToString() + "\"");
                strCommand.Append(",nombre=\"" + WLMFunctions.comillas(nombre.ToString()) + "\"");
                strCommand.Append(",email=\"" + WLMFunctions.comillas(email.ToString()) + "\"");
                strCommand.Append(",url='" + Convert.ToString(url) + "'");
                strCommand.Append(",contenido=\"" + WLMFunctions.comillas(contenido.ToString()) + "\"");
                strCommand.Append(",idEntry=\"" + idEntry.ToString() + "\"");
                strCommand.Append(",activo='" + Convert.ToInt16(Activo) + "'");
                strCommand.Append(" WHERE id=\"" + id + "\"");
                ConexionDBInterna.ExecuteCommand(strCommand.ToString());
                HttpContext.Current.Application.Remove("BlogComentariosPortada");
            }
            #endregion

        }

        [Serializable]
        public class FeedChannel
        {

            public string title {get;set; }
            private string _atom;

            public string atom
            {
               get;set;
             
            }
            private string _link;

            public string link
            {
               get;set;
        
            }
            private string _languaje;

            public string languaje
            {
               get;set;
           
            }
            private string _generator;

            public string generator
            {
               get;set;
             
            }

            [XmlElement("item")]
            public List<MiWebSiteBlogEntry> Feeds {get;set; }

            public FeedChannel()
            {
                Feeds = new List<MiWebSiteBlogEntry>();
            }
        }


        [Serializable]
        [XmlType("rss")]
        public class MiWebSiteBlogEntryCollection
        {
     
            private FeedChannel _channel;

            [XmlIgnore()]
            public List<MiWebSiteBlogEntry> BlogEntryList {get;set; }
            public FeedChannel channel {get;set; }
            
            public MiWebSiteBlogEntryCollection()
            {
            }

            public MiWebSiteBlogEntryCollection(ref dbConnector ConexionDB)
            {
           
                MWSModuleConfiguration blogConfig = MWSModuleConfiguration.GetConfig("MiWebSiteConfiguration/BlogCofig");
                string strCommand = "SELECT id FROM blogEntry order by id desc limit " + blogConfig.counts["frontPage"].value;

                OdbcDataReader reader = ConexionDB.ExecuteReader(strCommand);
                BlogEntryList = new List<MiWebSiteBlogEntry>();
                channel = new FeedChannel();
                channel.title = CurrentDomain.DomainName + " Blog";
                channel.link = "http://" + CurrentDomain.DomainName + "/rss";
                while (reader.Read())
                {
                    MiWebSiteBlogEntry newEntry = new MiWebSiteBlogEntry(Convert.ToInt32(reader["id"]),ref ConexionDB);
                    channel.Feeds.Add(newEntry);
                    BlogEntryList.Add(newEntry);
                }
                reader.Close();
                reader.Dispose();
            }

            public MiWebSiteBlogEntryCollection( int pageNumber, ref dbConnector ConexionDB)
            {
        
                string strCommand = "SELECT id FROM blogEntry order by id desc Limit " + ((pageNumber - 1) * 10) + ",10";

                OdbcDataReader reader = ConexionDB.ExecuteReader(strCommand);
                BlogEntryList = new List<MiWebSiteBlogEntry>();
                while (reader.Read())
                {
                    MiWebSiteBlogEntry newEntry = new MiWebSiteBlogEntry(Convert.ToInt32(reader["id"]), ref ConexionDB);

                    BlogEntryList.Add(newEntry);
                }
                reader.Close();
                reader.Dispose();
            }

            public MiWebSiteBlogEntryCollection(MiWebSiteUser usuario, int pageNumber, ref dbConnector ConexionDB)
            {

                string strCommand = "SELECT id FROM blogEntry WHERE idUsuario='" + usuario.id + "'  ORDER BY id desc Limit " + ((pageNumber - 1) * 10) + ",10";

                OdbcDataReader reader = ConexionDB.ExecuteReader(strCommand);
                BlogEntryList = new List<MiWebSiteBlogEntry>();
                while (reader.Read())
                {
                    MiWebSiteBlogEntry newEntry = new MiWebSiteBlogEntry(Convert.ToInt32(reader["id"]), ref ConexionDB);
                    BlogEntryList.Add(newEntry);
                }
                reader.Close();
                reader.Dispose();
            }

            public MiWebSiteBlogEntryCollection(string TagorCat, int pageNumber, bool tags, ref dbConnector ConexionDB)
            {
                string strCommand;
                if (tags)

                    strCommand = "SELECT E.id FROM blogEntry E LEFT JOIN BLOGTAG2ENTRY T on T.idEntry=E.id WHERE T.idTag ='" + new MiWebSiteBlogTag(TagorCat,ref ConexionDB).id + "' ORDER BY E.id desc Limit " + ((pageNumber - 1) * 10) + ",10";
                else
                    strCommand = "SELECT E.id FROM blogEntry E LEFT JOIN BLOGCAT2ENTRY C on C.idEntry=E.id WHERE C.idCat ='" + new MiWebSiteBlogCategoria(TagorCat,ref ConexionDB).id + "' ORDER BY E.id desc Limit " + ((pageNumber - 1) * 10) + ",10";

                OdbcDataReader reader = ConexionDB.ExecuteReader(strCommand);
                BlogEntryList = new List<MiWebSiteBlogEntry>();
                channel = new FeedChannel();
                channel.title = CurrentDomain.DomainName + " Blog Listado por Tag: " + TagorCat;
                channel.link = "http://" + CurrentDomain.DomainName + "/rss";
                while (reader.Read())
                {
                    MiWebSiteBlogEntry newEntry = new MiWebSiteBlogEntry(Convert.ToInt32(reader["id"]), ref ConexionDB);
                    channel.Feeds.Add(newEntry);
                    BlogEntryList.Add(newEntry);
                }
                reader.Close();
                reader.Dispose();
            }

            public MiWebSiteBlogEntryCollection(MiWebSiteBlogEntry entry, ref dbConnector ConexionDB)
            {
                BlogEntryList = new List<MiWebSiteBlogEntry>();
                foreach (MiWebSiteBlogCategoria categoria in entry.Categorias)
                {
                    foreach (MiWebSiteBlogEntry relEntry in new MiWebSiteBlogEntryCollection(categoria.SystemName, 1, false,ref  ConexionDB).BlogEntryList)
                    {
                        if(relEntry.id!=entry.id)
                            if (BlogEntryList.Find(o => o.id == relEntry.id) == null)
                            {
                                BlogEntryList.Add(relEntry);
                            }
                    }
                }
                foreach (MiWebSiteBlogTag tag in entry.Tags)
                {
                    foreach (MiWebSiteBlogEntry relEntry in new MiWebSiteBlogEntryCollection(tag.SystemName, 1, true, ref  ConexionDB).BlogEntryList)
                    {
                        if (relEntry.id != entry.id)
                            if (BlogEntryList.Find(o => o.id == relEntry.id) == null)
                            {
                                BlogEntryList.Add(relEntry);
                            }
                    }
                }

            }
        }

        public class MiWebSiteBlogCommentaryCollection
        {

            

            public List<MiWebSiteBlogComentary> BlogCommentaryList {get;set; }

            public MiWebSiteBlogCommentaryCollection(int cantidad, ref dbConnector ConexionDB)
            {
                
                string strCommand = "SELECT id FROM blogComentarios WHERE activo=1 AND idEntry<>0 order by id desc limit " + cantidad;

                OdbcDataReader reader = ConexionDB.ExecuteReader(strCommand);
                BlogCommentaryList = new List<MiWebSiteBlogComentary>();
                while (reader.Read())
                {
                    MiWebSiteBlogComentary newEntry = new MiWebSiteBlogComentary(Convert.ToInt32(reader["id"]),ref ConexionDB);

                    BlogCommentaryList.Add(newEntry);
                }
                reader.Close();
                reader.Dispose();
            }

            //public string Portada(bool todos)
            //{
            //    if (Convert.ToString(HttpContext.Current.Application["BlogComentariosPortada"]) == "")
            //    {
            //        int x = 0;
            //        StringBuilder salidaApplication = new StringBuilder();
            //        salidaApplication.Append("<Div");
            //        MiWebSiteTemplate template = new MiWebSiteTemplate("ComentarioPortada",ref ConexionDB);
            //        string skin = template.template.ToString();
            //        foreach (MiWebSiteBlogComentary item in _commentList)
            //        {

            //            string salida = skin.ToString();
            //            salida = salida.Replace("[NOMBRE]", item.nombre.ToString());
            //            salida = salida.Replace("[FECHA]", item.fechaCreacion.ToString("yy.MM.dd.HH.mm.ss"));
            //            salida = salida.Replace("[TITULO]", item.TituloEntry);
            //            salida = salida.Replace("[LINK]", item.Link);
            //            salidaApplication.Append(salida);

            //            x++;

            //        }
            //        salidaApplication.Append("</div>");


            //        HttpContext.Current.Application["BlogComentariosPortada"] = salidaApplication.ToString();
            //    }

            //    return HttpContext.Current.Application["BlogComentariosPortada"].ToString();

            //}

            public string XMLFeed()
            {
                StringBuilder salida = new StringBuilder();
                salida.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><rss version=\"2.0\" " +
        "xmlns:content=\"http://purl.org/rss/1.0/modules/content/\" " +
        "xmlns:dc=\"http://purl.org/dc/elements/1.1/\" " +
        "xmlns:atom=\"http://www.w3.org/2005/Atom\" " +
        "xmlns:sy=\"http://purl.org/rss/1.0/modules/syndication/\" " +
    "		> " +
    "<channel> " +
        "<title>Comentarios en " + ConfigurationManager.AppSettings["tituloWebSite"] + "</title> " +
        "<atom:link href=\"" + ConfigurationManager.AppSettings["siteURL"] + "feeds/comentarios\" rel=\"self\" type=\"application/rss+xml\" /> " +
        "<link>" + ConfigurationManager.AppSettings["siteURL"] + "feeds/comentarios</link> " +
        "<description>" + ConfigurationManager.AppSettings["tituloWebSite"] + "</description> " +
        "<lastBuildDate>" + DateTime.Now.ToString("R") + "</lastBuildDate> " +
        "<sy:updatePeriod>hourly</sy:updatePeriod> " +
        "<sy:updateFrequency>1</sy:updateFrequency> " +
        "<generator>MiWebSite Content Manager</generator>");


                foreach (MiWebSiteBlogComentary comentario in BlogCommentaryList)
                {
                    salida.Append("<item> " +
        "	<title>Por: " + comentario.nombre + "</title> " +
        "	<link>" + ConfigurationManager.AppSettings["siteURL"] + "</link> " +
        "	<dc:creator>" + SecurityElement.Escape(comentario.nombre) + "</dc:creator> " +
        "	<pubDate>" + comentario.fechaCreacion.ToString("R") + "</pubDate> " +
        "	<guid isPermaLink=\"false\">" + ConfigurationManager.AppSettings["siteURL"] + "</guid> " +
        "	<description>" + SecurityElement.Escape(comentario.contenido.Replace("<br>", "<br/>")) + "</description> " +
        "	<content:encoded><![CDATA[" + SecurityElement.Escape(comentario.contenido.Replace("<br>", "<br/>")) + "]]></content:encoded> " +
        "</item>");
                }

                salida.Append("</channel></rss>");

                return salida.ToString();
            }
        }

        public class MiWebSiteBlogTag : BaseClass
        {
            #region private fields
            private String _nombreTag;
            private string _systemName;
            #endregion

            #region public properties
            public String NombreTag {get;set; }
            public String SystemName {get;set; }
            #endregion

            #region constructors
            public MiWebSiteBlogTag()
            {
            }

            public MiWebSiteBlogTag(ref dbConnector ConexionDB)
            {
                ConexionDBInterna = ConexionDB;
                WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDB);
                id = classBinder.NewRecord("BLOGTAGS");
                string queryString = "";
                queryString = "SELECT * FROM BLOGTAGS WHERE id=\"" + id + "\"";
                GetRecord(queryString);
            }

            public MiWebSiteBlogTag(int registryId, ref dbConnector ConexionDB)
            {
                ConexionDBInterna = ConexionDB;
                string queryString = "";
                queryString = "SELECT * FROM BLOGTAGS WHERE id='" + registryId + "'";
                WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDB);
                this.GetRecord(queryString);
            }

            public MiWebSiteBlogTag(string TagName, ref dbConnector ConexionDB)
            {
                ConexionDBInterna = ConexionDB;
                string queryString = "";
                queryString = "SELECT * FROM BLOGTAGS WHERE SystemName='" + TagName + "'";
                WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDB);
                this.GetRecord(queryString);
            }
            #endregion

            #region public methods
            public void Delete()
            {
                string queryString = "";
                queryString = "DELETE FROM BLOGTAGS WHERE id=\"" + id + "\"";
                ConexionDBInterna.ExecuteCommand(queryString);

            }
            #endregion


            #region Private Methods
            private void GetRecord(string queryString)
            {
                OdbcDataReader reader = ConexionDBInterna.ExecuteReader(queryString);
                if (reader.HasRows)
                {
                    if (!reader.IsDBNull(reader.GetOrdinal("id")))
                        id = (System.Int32)reader["id"];
                    if (!reader.IsDBNull(reader.GetOrdinal("fechaCreacion")))
                        fechaCreacion = Convert.ToDateTime(reader["fechaCreacion"]); if (!reader.IsDBNull(reader.GetOrdinal("fechaModificacion"))) fechaModificacion = Convert.ToDateTime(reader["fechaModificacion"]); if (!reader.IsDBNull(reader.GetOrdinal("idUsuarioModificacion"))) idUsuarioModificacion = (System.Int32)reader["idUsuarioModificacion"];

                    if (!reader.IsDBNull(reader.GetOrdinal("idUsuario")))
                        idUsuario = (System.Int32)reader["idUsuario"];
                    if (!reader.IsDBNull(reader.GetOrdinal("nombreTag")))
                        NombreTag = (System.String)reader["nombreTag"];
                    if (!reader.IsDBNull(reader.GetOrdinal("systemName")))
                        SystemName = (System.String)reader["systemName"];
                }
            }

            protected override void UpdateBind()
            {
                StringBuilder strCommand = new StringBuilder();
                strCommand.Append("UPDATE BLOGTAGS set "); strCommand.Append("fechaModificacion='" + this.fechaModificacion.ToString("yyyy-MM-dd HH:mm:ss") + "'"); strCommand.Append(",idUsuarioModificacion=\"" + idUsuarioModificacion.ToString() + "\"");

                strCommand.Append(",nombreTag=\"" + WLMFunctions.comillas(NombreTag) + "\"");
                strCommand.Append(",systemName=\"" + WLMFunctions.comillas(SystemName) + "\"");
                strCommand.Append(" WHERE id=\"" + id + "\"");
                ConexionDBInterna.ExecuteCommand(strCommand.ToString());
            }
            #endregion
        }

        public class MiWebSiteBlogTagCollection
        {

            public List<MiWebSiteBlogTag> Elementos {get;set; }
            public MiWebSiteBlogTagCollection(ref dbConnector ConexionDB)
            {
           
                string strCommand = "SELECT id FROM BLOGTAGS order by nombreTag";
                OdbcDataReader reader = ConexionDB.ExecuteReader(strCommand);
                Elementos = new List<MiWebSiteBlogTag>();
                while (reader.Read())
                {
                    MiWebSiteBlogTag newEntry = new MiWebSiteBlogTag(Convert.ToInt32(reader["id"]),ref ConexionDB);


                    Elementos.Add(newEntry);
                }
                reader.Close();
                reader.Dispose();
            }

            public MiWebSiteBlogTagCollection(MiWebSiteBlogEntry entry, ref dbConnector ConexionDB)
            {
     
                string strCommand = "SELECT T.id FROM BLOGTAGS T left join BLOGTAG2ENTRY D on D.idTag=T.id WHERE D.idEntry='" + entry.id + "' order by nombreTag";

                OdbcDataReader reader = ConexionDB.ExecuteReader(strCommand);
                Elementos = new List<MiWebSiteBlogTag>();
                while (reader.Read())
                {
                    MiWebSiteBlogTag newEntry = new MiWebSiteBlogTag(Convert.ToInt32(reader["id"]),ref ConexionDB);


                    Elementos.Add(newEntry);
                }
                reader.Close();
                reader.Dispose();
            }
        }

        public class MiWebSiteBlogCategoria : BaseClass
        {
            #region private fields
            private String _nombreCategoria;
            private string _systemName;
            #endregion

            #region public properties
            public String NombreCategoria {get;set; }
            public String SystemName {get;set; }
            #endregion

            #region constructors
            public MiWebSiteBlogCategoria()
            {
            }
            public MiWebSiteBlogCategoria(ref dbConnector ConexionDB)
            {
                ConexionDBInterna = ConexionDB;
                WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDB);
                id = classBinder.NewRecord("BLOGCATS");
                string queryString = "";
                queryString = "SELECT * FROM BLOGCATS WHERE id=\"" + id + "\"";
                GetRecord(queryString);
            }

            public MiWebSiteBlogCategoria(int registryId, ref dbConnector ConexionDB)
            {
                ConexionDBInterna = ConexionDB;
                string queryString = "";
                queryString = "SELECT * FROM BLOGCATS WHERE id='" + registryId + "'";
                WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDB);
                this.GetRecord(queryString);
            }

            public MiWebSiteBlogCategoria(string nombreCat, ref dbConnector ConexionDB)
            {
                ConexionDBInterna = ConexionDB;
                string queryString = "";
                queryString = "SELECT * FROM BLOGCATS WHERE SystemName='" + nombreCat + "'";
                WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDB);
                this.GetRecord(queryString);
            }
            #endregion

            #region public methods

            public void Delete()
            {
                string queryString = "";
                queryString = "DELETE FROM BLOGCATS WHERE id=\"" + id + "\"";
                ConexionDBInterna.ExecuteCommand(queryString);

            }
            #endregion

            #region Private Methods
            private void GetRecord(string queryString)
            {
                OdbcDataReader reader = ConexionDBInterna.ExecuteReader(queryString);
                if (reader.HasRows)
                {
                    if (!reader.IsDBNull(reader.GetOrdinal("id")))
                        id = (System.Int32)reader["id"];
                    if (!reader.IsDBNull(reader.GetOrdinal("fechaCreacion")))
                        fechaCreacion = Convert.ToDateTime(reader["fechaCreacion"]); if (!reader.IsDBNull(reader.GetOrdinal("fechaModificacion"))) fechaModificacion = Convert.ToDateTime(reader["fechaModificacion"]); if (!reader.IsDBNull(reader.GetOrdinal("idUsuarioModificacion"))) idUsuarioModificacion = (System.Int32)reader["idUsuarioModificacion"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idUsuario")))
                        idUsuario = (System.Int32)reader["idUsuario"];
                    if (!reader.IsDBNull(reader.GetOrdinal("nombreCategoria")))
                        NombreCategoria = (System.String)reader["nombreCategoria"];
                    if (!reader.IsDBNull(reader.GetOrdinal("systemName")))
                        SystemName = (System.String)reader["systemName"];
                }
            }

            protected override void UpdateBind()
            {
                StringBuilder strCommand = new StringBuilder();
                strCommand.Append("UPDATE BLOGCATS set "); strCommand.Append("fechaModificacion='" + this.fechaModificacion.ToString("yyyy-MM-dd HH:mm:ss") + "'"); strCommand.Append(",idUsuarioModificacion=\"" + idUsuarioModificacion.ToString() + "\"");

                strCommand.Append(",nombreCategoria=\"" + NombreCategoria.ToString() + "\"");
                strCommand.Append(",systemName=\"" + SystemName.ToString() + "\"");
                strCommand.Append(" WHERE id=\"" + id + "\"");
                ConexionDBInterna.ExecuteCommand(strCommand.ToString());
            }
            #endregion
        }

        public class MiWebSiteBlogCategoriaCollection
        {
            private List<MiWebSiteBlogCategoria> _items;

            public List<MiWebSiteBlogCategoria> Elementos {get;set; }
            public MiWebSiteBlogCategoriaCollection(ref dbConnector ConexionDB)
            {
             
                string strCommand = "SELECT id FROM BLOGCATS order by nombreCategoria";

                OdbcDataReader reader = ConexionDB.ExecuteReader(strCommand);
                Elementos = new List<MiWebSiteBlogCategoria>();
                while (reader.Read())
                {
                    MiWebSiteBlogCategoria newEntry = new MiWebSiteBlogCategoria(Convert.ToInt32(reader["id"]),ref ConexionDB);

                    Elementos.Add(newEntry);
                }
                reader.Close();
                reader.Dispose();
            }

            public MiWebSiteBlogCategoriaCollection(MiWebSiteBlogEntry entry, ref dbConnector ConexionDB)
            {
    
                string strCommand = "SELECT C.id FROM BLOGCATS C left join BLOGCAT2ENTRY D on D.idCat=C.id WHERE D.idEntry='" + entry.id + "' order by nombreCategoria";

                OdbcDataReader reader = ConexionDB.ExecuteReader(strCommand);
                Elementos = new List<MiWebSiteBlogCategoria>();
                while (reader.Read())
                {
                    MiWebSiteBlogCategoria newEntry = new MiWebSiteBlogCategoria(Convert.ToInt32(reader["id"]),ref ConexionDB);

                    Elementos.Add(newEntry);
                }
                reader.Close();
                reader.Dispose();
            }
        }

        public class MiWebSiteBlogTag2Entry : BaseClass
        {
            #region private fields
            private int _Id;
            private int _idEntry;
            private int _idTag;
            #endregion

            #region public properties
            public int Id {get;set; }
            public int idEntry {get;set; }
            public int idTag {get;set; }
            #endregion

            #region constructors
            public MiWebSiteBlogTag2Entry(ref dbConnector ConexionDB)
            {
                ConexionDBInterna = ConexionDB;
                WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDB);
                id = classBinder.NewRecord("BLOGTAG2ENTRY");
                string queryString = "";
                queryString = "SELECT * FROM BLOGTAG2ENTRY WHERE id=\"" + id + "\"";
                GetRecord(queryString);
            }

            public MiWebSiteBlogTag2Entry(int registryId, ref dbConnector ConexionDB)
            {
                ConexionDBInterna = ConexionDB;
                string queryString = "";
                queryString = "SELECT * FROM BLOGTAG2ENTRY WHERE id='" + registryId + "'";
                WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDB);
                this.GetRecord(queryString);
            }
            #endregion

            #region public methods

            public void Delete()
            {
                string queryString = "";
                queryString = "DELETE FROM BLOGTAG2ENTRY WHERE id=\"" + id + "\"";
                ConexionDBInterna.ExecuteCommand(queryString);

            }
            #endregion


            #region Private Methods
            private void GetRecord(string queryString)
            {
                OdbcDataReader reader = ConexionDBInterna.ExecuteReader(queryString);
                if (reader.HasRows)
                {
                    if (!reader.IsDBNull(reader.GetOrdinal("Id")))
                        Id = (System.Int32)reader["Id"];
                    if (!reader.IsDBNull(reader.GetOrdinal("fechaCreacion")))
                        fechaCreacion = Convert.ToDateTime(reader["fechaCreacion"]); if (!reader.IsDBNull(reader.GetOrdinal("fechaModificacion"))) fechaModificacion = Convert.ToDateTime(reader["fechaModificacion"]); if (!reader.IsDBNull(reader.GetOrdinal("idUsuarioModificacion"))) idUsuarioModificacion = (System.Int32)reader["idUsuarioModificacion"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idUsuario")))
                        idUsuario = (System.Int32)reader["idUsuario"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idEntry")))
                        idEntry = (System.Int32)reader["idEntry"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idTag")))
                        idTag = (System.Int32)reader["idTag"];
                }
            }


            protected override void UpdateBind()
            {
                StringBuilder strCommand = new StringBuilder();
                strCommand.Append("UPDATE BLOGTAG2ENTRY set "); strCommand.Append("fechaModificacion='" + this.fechaModificacion.ToString("yyyy-MM-dd HH:mm:ss") + "'"); strCommand.Append(",idUsuarioModificacion=\"" + idUsuarioModificacion.ToString() + "\"");
                strCommand.Append(",id=\"" + id.ToString() + "\"");
                strCommand.Append(",idEntry=\"" + idEntry.ToString() + "\"");
                strCommand.Append(",idTag=\"" + idTag.ToString() + "\"");
                strCommand.Append(" WHERE id=\"" + id + "\"");
                ConexionDBInterna.ExecuteCommand(strCommand.ToString());
            }
            #endregion
        }

        public class MiWebSiteBlogCat2Entry : BaseClass
        {
            #region private fields
            private int _Id;
            private int _idEntry;
            private int _idCat;
            #endregion

            #region public properties
            public int Id {get;set; }
            public int idEntry {get;set; }
            public int idCat {get;set; }
            #endregion

            #region constructors
            public MiWebSiteBlogCat2Entry(ref dbConnector ConexionDB)
            {
                ConexionDBInterna = ConexionDB;
                WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDB);
                id = classBinder.NewRecord("BLOGCAT2ENTRY");
                string queryString = "";
                queryString = "SELECT * FROM BLOGCAT2ENTRY WHERE id=\"" + id + "\"";
                GetRecord(queryString);
            }

            public MiWebSiteBlogCat2Entry(int registryId, ref dbConnector ConexionDB)
            {
                ConexionDBInterna = ConexionDB;
                string queryString = "";
                queryString = "SELECT * FROM BLOGCAT2ENTRY WHERE id='" + registryId + "'";
                WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDB);
                this.GetRecord(queryString);
            }
            #endregion

            #region public methods

            public void Delete()
            {
                string queryString = "";
                queryString = "DELETE FROM BLOGCAT2ENTRY WHERE id=\"" + id + "\"";
                ConexionDBInterna.ExecuteCommand(queryString);

            }
            #endregion

            #region Private Methods
            private void GetRecord(string queryString)
            {
                OdbcDataReader reader = ConexionDBInterna.ExecuteReader(queryString);
                if (reader.HasRows)
                {
                    if (!reader.IsDBNull(reader.GetOrdinal("Id")))
                        Id = (System.Int32)reader["Id"];
                    if (!reader.IsDBNull(reader.GetOrdinal("fechaCreacion")))
                        fechaCreacion = Convert.ToDateTime(reader["fechaCreacion"]); if (!reader.IsDBNull(reader.GetOrdinal("fechaModificacion"))) fechaModificacion = Convert.ToDateTime(reader["fechaModificacion"]); if (!reader.IsDBNull(reader.GetOrdinal("idUsuarioModificacion"))) idUsuarioModificacion = (System.Int32)reader["idUsuarioModificacion"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idUsuario")))
                        idUsuario = (System.Int32)reader["idUsuario"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idEntry")))
                        idEntry = (System.Int32)reader["idEntry"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idCat")))
                        idCat = (System.Int32)reader["idCat"];
                }
            }


            protected override void UpdateBind()
            {
                StringBuilder strCommand = new StringBuilder();
                strCommand.Append("UPDATE BLOGCAT2ENTRY set "); strCommand.Append("fechaModificacion='" + this.fechaModificacion.ToString("yyyy-MM-dd HH:mm:ss") + "'"); strCommand.Append(",idUsuarioModificacion=\"" + idUsuarioModificacion.ToString() + "\"");
                strCommand.Append(",Id=\"" + id.ToString() + "\"");
                strCommand.Append(",idEntry=\"" + idEntry.ToString() + "\"");
                strCommand.Append(",idCat=\"" + idCat.ToString() + "\"");
                strCommand.Append(" WHERE id=\"" + id + "\"");
                ConexionDBInterna.ExecuteCommand(strCommand.ToString());
            }
            #endregion
        }

        public class BlogEntry2Dominio : BaseClass
        {
            #region private fields
            private int _idEntry;
            private int _idDominio;
            #endregion

            #region public properties
            public int idEntry {get;set; }
            public int idDominio {get;set; }
            #endregion

            #region constructors
            public BlogEntry2Dominio(dbConnector dbConn)
            {
                ConexionDBInterna = dbConn;
                WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDBInterna);
                id = classBinder.NewRecord("BLOGENTRY2DOMINIO");
                string queryString = "";
                queryString = "SELECT * FROM BLOGENTRY2DOMINIO WHERE id='" + id + "'";
                GetRecord(queryString);
            }

            public BlogEntry2Dominio(int registryId, dbConnector dbConn)
            {
                ConexionDBInterna = dbConn;
                string queryString = "";
                queryString = "SELECT * FROM BLOGENTRY2DOMINIO WHERE id='" + registryId + "'";
                WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDBInterna);
                this.GetRecord(queryString);
            }
            public BlogEntry2Dominio(DataRow dataRow, dbConnector dbConn)
            {
                ConexionDBInterna = dbConn;
                this.GetRecord(dataRow);
            }
            #endregion

            #region public methods


            public void Delete()
            {
                string queryString = "";
                queryString = "DELETE FROM BLOGENTRY2DOMINIO WHERE id='" + id + "'";
                ConexionDBInterna.ExecuteCommand(queryString);

            }
            #endregion


            #region Private Methods
            private void GetRecord(string queryString)
            {
                OdbcDataReader reader = ConexionDBInterna.ExecuteReader(queryString);
                if (reader.HasRows)
                {
                    if (!reader.IsDBNull(reader.GetOrdinal("id")))
                        id = (System.Int32)reader["id"];
                    if (!reader.IsDBNull(reader.GetOrdinal("fechaCreacion")))
                        fechaCreacion = Convert.ToDateTime(reader["fechaCreacion"]);
                    if (!reader.IsDBNull(reader.GetOrdinal("fechaModificacion")))
                        fechaModificacion = Convert.ToDateTime(reader["fechaModificacion"]);
                    if (!reader.IsDBNull(reader.GetOrdinal("idUsuario")))
                        idUsuario = (System.Int32)reader["idUsuario"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idUsuarioModificacion")))
                        idUsuarioModificacion = (System.Int32)reader["idUsuarioModificacion"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idEntry")))
                        idEntry = (System.Int32)reader["idEntry"];
                    if (!reader.IsDBNull(reader.GetOrdinal("idDominio")))
                        idDominio = (System.Int32)reader["idDominio"];
                }
            }


            private void GetRecord(DataRow dataRow)
            {
                if (dataRow != null)
                {
                    if (dataRow["id"] != null)
                        id = (System.Int32)dataRow["id"];
                    if (dataRow["fechaCreacion"] != null)
                        fechaCreacion = (System.DateTime)dataRow["fechaCreacion"];
                    if (dataRow["fechaModificacion"] != null)
                        fechaModificacion = (System.DateTime)dataRow["fechaModificacion"];
                    if (dataRow["idUsuario"] != null)
                        idUsuario = (System.Int32)dataRow["idUsuario"];
                    if (dataRow["idUsuarioModificacion"] != null)
                        idUsuarioModificacion = (System.Int32)dataRow["idUsuarioModificacion"];
                    if (dataRow["idEntry"] != null)
                        idEntry = (System.Int32)dataRow["idEntry"];
                    if (dataRow["idDominio"] != null)
                        idDominio = (System.Int32)dataRow["idDominio"];
                }
            }


            protected override void UpdateBind()
            {
                StringBuilder strCommand = new StringBuilder();
                strCommand.Append("UPDATE BLOGENTRY2DOMINIO set ");
                strCommand.Append("fechaModificacion='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");
                strCommand.Append(",idUsuarioModificacion='" + idUsuarioModificacion.ToString() + "'");
                strCommand.Append(",idEntry='" + idEntry.ToString() + "'");
                strCommand.Append(",idDominio='" + idDominio.ToString() + "'");
                strCommand.Append(" WHERE id='" + id + "'");
                ConexionDBInterna.ExecuteCommand(strCommand.ToString());
            }
            #endregion
        }

        public class BlogEntry2DominioCollection
        {
            private dbConnector ConexionDB;
            private BaseClassArray<BlogEntry2Dominio> _items;
            public BaseClassArray<BlogEntry2Dominio> Elementos {get;set; }
            public BlogEntry2DominioCollection()
            {
            }
            public BlogEntry2DominioCollection(dbConnector dbConn)
            {
                ConexionDB = dbConn;
                string strCommand = "SELECT id FROM BLOGENTRY2DOMINIO ";
                OdbcDataReader dataReader = ConexionDB.ExecuteReader(strCommand);
                Elementos = new BaseClassArray<BlogEntry2Dominio>();
                while (dataReader.Read())
                {
                    BlogEntry2Dominio newItem = new BlogEntry2Dominio(Convert.ToInt32(dataReader["id"]), ConexionDB);
                    Elementos.Add(newItem);
                }
                dataReader.Close();
                dataReader.Dispose();
            }
        }

        public struct RespuestaPost
        {
            private bool _sucess;

            public bool Sucess
            {
               get;set;
         
            }

            private string _errorMessage;

            public string ErrorMessage
            {
               get;set;
         
            }


            private MiWebSiteBlogEntry _blogEntry;

            public MiWebSiteBlogEntry BlogEntry
            {
               get;set;
      
            }
        }

        public class BlogFunctions
        {
            public static void LoadIncludes(MiWebSitePage pagina)
            {
            }

            public static void LoadIncludesAdmin(MiWebSitePage pagina)
            {
                pagina.Scripts.Add("/jquery/jquery.scrollTo.js");
                pagina.Scripts.Add("/blog/script/admin.js");
                pagina.Scripts.Add("http://maps.google.com/maps/api/js?sensor=false&amp;language=es");
                pagina.Scripts.Add("/jquery/MapsAdmin.js");
            }
        }

        public class ObjetoPrueba
        {
            public string Propiedad { get; set; }
        }
}